package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.dto.RequestParams;
import com.hmall.common.pojo.ItemDoc;
import com.hmall.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;
    /**
     * 自动补全
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String key){
        return searchService.suggestion(key);
    }

    /**
     * 过滤项聚合功能
     * @param dto
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams dto){
        return searchService.filters(dto);
    }

    /**
     * 查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams dto){
        return searchService.list(dto);
    }
}
